<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @property float $lat 纬度
 * @property float $lng 经度
 * @property int $browse 浏览量
 * @property int $collect 收藏数
 * @property int $comment 评论数
 * @property int $id
 * @property int $level 星级
 * @property int $like 点赞数
 * @property int $store_id 商铺
 * @property int $users_id 用户
 * @property string $adcode
 * @property string $address 地址
 * @property string $city 城市
 * @property string $content 内容
 * @property string $createtime
 * @property string $images 图片
 * @property string $title 标题
 * @property-read \app\model\Store $store
 * @property-read \app\model\Users $users
 * @property-read \app\model\UsersCollect $users_collect
 * @property-read \app\model\UsersLike $users_like
 * @mixin \think\Model
 */
class StoreAssess extends Model
{
	use SoftDelete;
	protected $createTime = 'createtime';
	protected $deleteTime = 'deletetime';
	protected $updateTime = 'updatetime';

    public static function onBeforeInsert(Model $model): mixed
    {

        if (empty($model->getAttr('images'))){
            $images = Config::where(['name'=>'store_assess'])->value('value');
            $model->setAttr('images',$images);
        }
        return true;
    }

    function store()
    {
        return $this->belongsTo(Store::class,'store_id');
    }

    function users()
    {
        return $this->belongsTo(Users::class,'users_id');
    }

    public function usersLike()
    {
        return $this->hasOne(UsersLike::class,'pro_id');
    }

    public function usersCollect()
    {
        return $this->hasOne(UsersCollect::class,'pro_id');

    }

}
